﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class addNewTaskForm : Form
    {
        //lite globals
        Form1 form1;
        ServiceReference1.DatabaseClient test;

        public addNewTaskForm()
        {
            InitializeComponent();
        }
        
        public addNewTaskForm(int taskGroupId, ServiceReference1.DatabaseClient test, Form1 form1)
        {
            InitializeComponent();
            taskgroup_txt.Text = "" + taskGroupId;
            name_txt.Text = "";
            gradetype_txt.Text = "0";
            weight_txt.Text = "0";
            this.test = test;
            this.form1 = form1;
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            bool check = checkSomeShit();
            if (check)
            {
                test.AddTask(int.Parse(taskgroup_txt.Text), name_txt.Text, int.Parse(gradetype_txt.Text), int.Parse(weight_txt.Text));
                form1.updateListBox3();
                this.Close();
            }
            
        }

        private bool checkSomeShit()
        {
            taskgroup_txt.BackColor = Color.White;
            name_txt.BackColor = Color.White;
            gradetype_txt.BackColor = Color.White;
            weight_txt.BackColor = Color.White;
            warning_lbl1.Text = "";
            warning_lbl2.Text = "";
            warning_lbl3.Text = "";
            warning_lbl4.Text = "";

            if (taskgroup_txt.Text == "")
            {
                //System.Windows.Forms.MessageBox.Show("taskgroup_txt");
                taskgroup_txt.Select();
                taskgroup_txt.BackColor = Color.Orange;
                warning_lbl1.Text = "!";
                return false;
            }
            if (name_txt.Text == "")
            {
                //System.Windows.Forms.MessageBox.Show("name_txt");
                name_txt.Select();
                name_txt.BackColor = Color.Orange;
                warning_lbl2.Text = "!";
                return false;
            }
            if (gradetype_txt.Text == "")
            {
                //System.Windows.Forms.MessageBox.Show("gradetype_txt");
                gradetype_txt.Select();
                gradetype_txt.BackColor = Color.Orange;
                warning_lbl3.Text = "!";
                return false;
            }
            if (weight_txt.Text == "")
            {
                weight_txt.Select();
                weight_txt.BackColor = Color.Orange;
                //System.Windows.Forms.MessageBox.Show("weight_txt");
                warning_lbl4.Text = "!";
                return false;
            }

            try 
            { 
                int a = int.Parse(taskgroup_txt.Text);
                int b = int.Parse(gradetype_txt.Text);
                int c =  int.Parse(weight_txt.Text);
                return true;
            }
            catch (Exception e)
            {
                e = null;
            }
            System.Windows.Forms.MessageBox.Show("FU!");
            return false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
